<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            border:1px solid #000;
            margin:5px;
            line-height: 35px;
            font-size: 14px;
            padding: 4px 10px;
            list-style: none;
            width: 100%;
        }
        li:hover{
            background-color:#872657;
            transition:all 1s ease;
        }
        /* transition-group动画样式 */
        .v-enter,.v-leave-to{
            opacity: 0;
            transform: translateY(100px);
        }
        .v-enter-active,.v-leave-active{
            transition:all 1s ease;
        }
        /* 删除元素时要使用的样式 */
        .v-move{
            transition: all 0.6s ease;
        }
        .v-leave-active{
            position:absolute;
        }
    </style>
</head>
    <script src="vue.js"></script>
<body>
    <div id="app">
        课程id: <input type="text" v-model="id">
        课程名: <input type="text" v-model="course">
        <input type="button" value="添加" @click="add">
  
            <!-- transition标签 只能给单个DOM元素来添加动画效果 ，不能给v-for渲染出来的元素使用-->
            <!-- vue提供了一个叫transition-group的标签，来专门搞定v-for渲染出来的元素的动画 -->
            <transition-group tag="ul"  appear>
                <li v-for="item in list" :key="item.id" @click="del(item.id)">课程id:{{item.id}}------课程名:{{item.course}}</li>
            </transition-group>
        
    </div>

    <script>
        var vm = new Vue({
            el:'#app',
            data:{
                id:'',
                course:'',
                list:[
                    {id:1,course:'Javascript'},
                    {id:2,course:'数据库原理'},
                    {id:3,course:'操作系统'},
                ]
            },
            methods:{
                add:function(){
                    this.list.push({id:this.id,course:this.course});
                },
                del(id){
                    this.list.forEach((item,i) =>{
                        if(item.id == id){
                            this.list.splice(i,1);
                        }
                    })
                }
            }
        }) 
    </script>
</body>
</html>